﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL;
using System.Collections;
using ASPNETVN.PORTAL.Components.Configuration;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
using System.Data;

namespace CDTM.Modules.ADVERTISEMENT
{
    public enum ModulePages
    {
        Style1,
        Style2
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Define an Array List
            ArrayList list = new ArrayList();
            list.Add(new ListItem("Style1", "Style1"));
            list.Add(new ListItem("Style2", "Style2"));

            ModuleSettingItem itemSetting = new ModuleSettingItem(new CustomListDataType(list, "Text", "Value"));
            itemSetting.Value = "Style1";
            itemSetting.Name = "Hình thức hiển thị nội dung";
            itemSetting.Description = "Hình thức hiển thị nội dung ở trang chủ";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("DisplayStyle", itemSetting);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/CDTM.Modules.ADVERTISEMENT/";
            ModulePages page = (ModulePages)Enum.Parse(typeof(ModulePages), this.Settings["DisplayStyle"].ToString(), true);
            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadChildControl();
        }
    }
}